package com.ebupt.migu.ksms.controller;

import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ebupt.migu.common.sms.CallerHungUpMessageBean;
import com.ebupt.migu.common.sms.MegamarketRequestBean;
import com.ebupt.migu.ksms.service.SMSProducerService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author liuyangyang@e-byte.com
 * @description: TODO
 * @date 2024/9/4 16:41
 */
@Slf4j
@RestController()
@RequestMapping("/producer")
public class ProducerController {
    @Autowired
    SMSProducerService service;

    @RequestMapping("/send")
    public void send(@RequestParam("num") int num) {
        CallerHungUpMessageBean bean = new CallerHungUpMessageBean();
        MegamarketRequestBean megamarket = new MegamarketRequestBean();
        megamarket.setPort(3);
        megamarket.setContent("(中国移动 咪咕音乐)您此次参与宣发游戏的红包激活码为123456(回复ARE不再接收)");
        megamarket.setStrategyId("DX20240904180649117");
        megamarket.setTemplateId("20070001");
        for (int i = 0; i < num; i++) {
            megamarket.setMsisdn(generateRandomPhoneNumber());
            bean.setMegamarket(megamarket);
            log.info("第{}条模拟短信，短信内容为：{}", i, bean);
            service.sendMessage(bean);
        }
        log.info("Complete!");
    }

    public static String generateRandomPhoneNumber() {
        Random random = new Random();
        StringBuilder phoneNumber = new StringBuilder("1");
        for (int i = 0; i < 10; i++) {
            phoneNumber.append(random.nextInt(10));
        }
        return phoneNumber.toString();
    }
}
